package library;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import user_client.LibrarianUserClient;

public class AddingBookPane extends GuiTemplatePane {

	private TextPane infoEntry = null;
	private LibrarianUserClient client;
	private DepartmentButtonPane departmentButtonPane = 
			new DepartmentButtonPane(); 
	private EditionButtonPane editionButtonPane = 
			new EditionButtonPane();
	
	
	private Integer idOfDepartment = null;
	private String nameOfDepartment = "nie wybrano działu";
	private JPanel mainArea = null;
	
	private String nameOfEdition = "nie podano wydania";
	private Integer isbn = null;
	
	public AddingBookPane(JPanel mainArea, LibrarianUserClient client) {
		super(mainArea, "zarządzaj książkami");
		JPanel entity = new JPanel();
		entity.setLayout(new GridLayout(2,1));
		JPanel bottomPanel = new JPanel();
		this.mainArea = mainArea;
		
		this.client = client;
		//edition.setVisible(true);

		entity.add(departmentButtonPane);
		entity.add(editionButtonPane);
		//entity.add(departmentManagerPane, BorderLayout.SOUTH);
		this.setEntity(entity);
		//.add(new EditionBookPane());
	
	}
	
	private class DepartmentButtonPane extends JPanel {
		
		private JButton button = new JButton("wybierz dział");
		private JLabel label = new JLabel(nameOfDepartment);
		
		
		public DepartmentButtonPane() {
			this.setLayout(new GridLayout(2,1));
			button.addActionListener(new ShowDeprtmentActionListener());
			this.add(button);
			
		}
		
		private class ShowDeprtmentActionListener implements ActionListener {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JDialog frame = new JDialog();

				frame.add(new DepartmentManagerPane(client, idOfDepartment,
						nameOfDepartment, mainArea, frame));
				frame.setAlwaysOnTop(true);
				frame.setVisible(true);
				frame.setSize(400, 300);
				frame.setResizable(false);
				mainArea.getParent().setEnabled(false);
				//mainArea.add(frame);
				
			}
			
		}
	}
	
	
	private class EditionButtonPane extends JPanel {
		
		private JButton button = new JButton("wydanie");
		private JLabel label = new JLabel(nameOfEdition);
		
		
		public EditionButtonPane() {
			this.setLayout(new GridLayout(2,1));
			button.addActionListener(new ShowEditionActionListener());
			this.add(button);
			
		}
		
		private class ShowEditionActionListener implements ActionListener {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JDialog frame = new JDialog();

				frame.add(new EditionBookPane(client, isbn,
						nameOfEdition, mainArea));
				frame.setAlwaysOnTop(true);
				frame.setVisible(true);
				frame.setSize(400, 300);
				frame.setResizable(false);
				mainArea.getParent().setEnabled(false);
				//mainArea.add(frame);
				
			}
			
		}
	}
	
}
